/*
 * Created on 17 �.�. 2547
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.softplus.carrefour.hd.bltier.admin;

import java.util.HashMap;
import java.util.List;
import java.util.Vector;

import net.sf.hibernate.HibernateException;

import com.epro.standard.frontend.lov.LOVKeyword;

import com.softplus.carrefour.CFException;
import com.softplus.carrefour.hd.bltier.db.HibernateUtil;
import com.softplus.carrefour.hd.bltier.entity.CfhdSystem;
import com.softplus.carrefour.hd.bltier.util.LOVtemplate;

/**
 * @author Kowit
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class CFHDSystemManage implements ICFHDSystemControl, 
                                         ICFHDSystemViewer {

    /* (non-Javadoc)
     * @see com.softplus.carrefour.hd.bltier.admin.ICFHDSystemViewer#getLOVSystem()
     */

    public Vector getLOVSystem(LOVKeyword key) throws CFException {

        String searchValue = key.getMessage();
        Vector checkBoxs = key.getCheckBox();
        HashMap conds = key.getCondition();

        if (checkBoxs.size() == 0) { //no checkbox was checked 
            checkBoxs.addElement("0");
        }

        HashMap serachCols = new HashMap();

        serachCols.put("0", "CFHD_SYSTEM");
        String sql = 
            "select " + "CFHD_SYSTEM " + " from CFHD_SYSTEM " + " where (1=1) and (";

        return new LOVtemplate().getLOV(sql, new String[] { "CFHD_SYSTEM" }, 
                                        searchValue, serachCols, checkBoxs, 
                                        "CFHD_SYSTEM ", "");
    }

    public Vector getListSystem() throws CFException {
        List ls = null;
        try {
            ls = 
 HibernateUtil.getSession().createCriteria(CfhdSystem.class).list();
        } catch (HibernateException e) {
            e.printStackTrace();
        } finally {
            HibernateUtil.closeSession();
        }

        Vector system = new Vector();
        if ((ls != null) && (ls.size() > 0)) {
            for (int i = 0; i < ls.size(); i++) {
                system.addElement(((CfhdSystem)ls.get(i)).getCfhdSystem());
            }
        }
        return system;
    }
}
